#ifndef DIAGRAMVIDEO_H
#define DIAGRAMVIDEO_H

#include <QObject>
#include <QUuid>
#include <QThread>
#include <QGraphicsWidget>
#include "DiagramShape.h"

class QPaintThread;
class DiagramVideo : public QGraphicsWidget
{
	Q_OBJECT

public:
	enum {Type = UserType + VIDEO_TYPE};
	DiagramVideo(QObject *parent = 0);
	~DiagramVideo();
	int		type() const { return Type; }

	QPixmap			m_threadpixmap;
	QImage			m_threadimg;
protected:
	bool		event(QEvent * e );
	void		paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget  = 0 );
	bool		startPlayCamera();
	bool		stopPlayCamera();
	bool		getMatchSize(QRect& rt);
	bool		isChangeScreenSize();
	bool		isChangeCameraSize();
	bool		setSceneRect(QRectF& rt);
private:
	QUuid			m_uCameraID;
	QRect			m_rtScreenRect;
	QPaintThread*	m_pPaintThread;

	int				m_nCameraImgW;
	int				m_nCameraImgH;
	int				t_nCameraImgW;
	int				t_nCameraImgH;

	int				m_nScreenW;
	int				m_nScreenH;
	int				t_nScreenW;
	int				t_nScreenH;

	QRect			m_rtDisplay;

	QPixmap			m_staticmap;
	
protected slots:
	void		changesizeSlot(QSize);
};

class QPixmap;
class QPaintThread : public QThread{
	Q_OBJECT

public:
	QPaintThread(QObject* parent = 0);
	~QPaintThread();

	void		stop();
	void		setCameraUuid(QUuid& uuid);
protected:
	void		run();

private:
	QUuid		m_uCameraID;
	bool		m_bRunFlag;
	QImage*		m_pImage;
	QPixmap*	m_pNewPixmap;
	QObject*	m_pParent;
	QSize		m_szImg,t_szImg;
	BYTE*		m_byRaw;
	BITMAPINFO	m_bitmap;

signals:
	void		changesizeSignal(QSize);
};

#endif // DIAGRAMVIDEO_H
